package com.et114.components.simpletable;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

//import org.apache.commons.logging.Log;
//import org.apache.commons.logging.LogFactory;



public class DataList implements java.io.Serializable{
	private static final long	serialVersionUID	= 4547314928916392270L;
	//	private  Log logger = LogFactory.getLog( DataList.class );
	private int pageSize = 0; // 显示一页应该显示的记录数
	private int currentPage = 1; // 当前页数
	private int maxCount = 0; // 集合中的最大记录数,影响分页的形成;
	private Map addinInfo=new TreeMap();	; // 除标签之外的自定义查询字符串信息;
	private String uri = ""; // 重新定义分页导航链接
	private String pageKey = "page";
	public DataList(){}
	
	/**
	 * 
	 * @param list
	 * @param total
	 * @param pagenum 显示一页应该显示的记录数
	 * @param npage 当前页数
	 */
	public DataList( List list , int total , int pagenum , int npage ){
		this.nowlist = list;
		this.maxCount = total;
		this.pageSize = pagenum;
		this.currentPage = npage;
		
	}
	
	/**
	 * 数据载体
	 */
	private List nowlist = new ArrayList();

	public List getNowlist() {
		return nowlist;
	}

	public void setNowlist( List nowlist ) {
		this.nowlist = nowlist;
	}

	/**
	 * 
	 * 获得要提取的数据的起始位置
	 * 
	 * @return //
	 */
	public int getStart() {
		if ( this.currentPage * this.pageSize > this.maxCount )
			return ( this.getMaxPage() - 1) * this.pageSize + 1;
		return ( this.currentPage - 1 ) * this.pageSize + 1;
	}

	/**
	 * 获得提取的数据的结束位置
	 * 
	 * @return //
	 */
	public int getEnd() {
		if ( this.currentPage * this.pageSize > this.maxCount )
			return this.maxCount;
		return ( this.currentPage ) * this.pageSize;
	}

	public int getMaxPage() {
		int maxPage = ( int ) Math.ceil( ( double ) this.maxCount 
				/ ( double ) this.pageSize );
		if ( maxPage <= 0 )
			maxPage = 1;

		return maxPage;
	}

	/**
	 * 获得查询字符串中分页的键值
	 * 
	 * @return //
	 */
	public String getPageKey() {
		return pageKey;
	}

	/**
	 * 获得上一个页的索引
	 * 
	 * @return //
	 */
	public int getPrevPage() {
		int prevPage = this.getCurrentPage() - 1;
		if ( prevPage <= 0 )
			prevPage = 1;
		return prevPage;
	}

	/**
	 * 获得下一个页的索引
	 * 
	 * @return //
	 */
	public int getNextPage() {
		int nextPage = this.getCurrentPage() + 1;
		if ( nextPage > this.getMaxPage() )
			nextPage = this.getMaxPage();
		return nextPage;
	}

	/**
	 * 获得分页大小
	 * 
	 * @return //
	 */
	public int getPageSize() {
		return pageSize;
	}

	/**
	 * 设置分页大小
	 * 
	 * @param pageSize
	 */
	public void setPageSize( int pageSize ) {
		this.pageSize = pageSize;
	}

	/**
	 * 获得当前页码
	 * 
	 * @return int
	 */
	public int getCurrentPage() {
		int maxPage = this.getMaxPage();
		if ( currentPage > maxPage )
			return maxPage;
		return currentPage;
	}

	public void setCurrentPage( int currentPage ) {
		this.currentPage = currentPage;
	}

	/**
	 * 获得计算分页时的总数量
	 * 
	 * @return //
	 */
	public int getMaxCount() {
		return maxCount;
	}

	public void setMaxCount( int maxCount ) {
		this.maxCount = maxCount;
	}

	/**
	 * 自定义在查询字符串上的信息,可以用它计算更复杂的数据提取; 所有以 w_[tagid]_[key] tagid:为标签的uid
	 * key为用户自定义的变量名称，用户可以随意定义即可； 例如: w_myId_name
	 * 
	 * @param key
	 * @param value
	 */
	public void addinInfo( String key , String value ) {
		addinInfo.put( key , value );
	}

	public Map getAddinInfo() {
		return addinInfo;
	}

	// public Map getQueryMap() {
	// return queryMap;
	// }

	/**
	 * @param string
	 */
	public void setPageKey( String string ) {
		pageKey = string;
	}

	/**
	 * @return
	 */
	public String getUri() {
		return uri;
	}

	/**
	 * @param string
	 */
	public void setUri( String string ) {
		uri = string;
	}
	
}
